package com.javaspeak.designpatterns.go4.creational.abstractfactory;

import com.javaspeak.designpatterns.go4.creational.abstractfactory.ShapeSelector.ShapeType;

/**
 * This application demonstrates the usage of the Gang of Four Structural
 * AbstractFactory pattern.  The idea behind the AbstractFactory pattern is
 * that the implementation can be switched by using a different Factory.
 * <p>
 * The Application uses ShapeSelector to choose the appropriate factory, get
 * the shape from that factory and then draw the shape.
 * <p>
 * The SquareFactory and TriangleFactory both implement ShapeFactory which
 * has a method called getShape();
 * <p>
 * The getShape() method in SquareFactory returns a Square and the
 * TriangleFactory returns a Triangle.
 * <p>
 * Both Square and Triangle implement Shape which has a drawShape() method.
 * <p>
 * The AbstractFactory pattern allows the underlying implementation to be
 * switched by using SquareFactory or TriangleFactory.
 * <p>
 * The AbstractFactory pattern is about having plugable factories that can be
 * plugged to provide different implementations.
 * <p>
 * In our Application example we can call drawShape on a shape and it will be
 * up to whether the SquareFactory or TriangleFactory was plugged in as to
 * whether a Square or Triangle gets drawn.
 *
 * @author John Dickerson
 */
public class ApplicationAbstractFactory {

    public void drawShapes(){

        ShapeSelector.getShapeFactory(
                ShapeType.SQUARE ).getShape().drawShape();

        ShapeSelector.getShapeFactory(
                ShapeType.TRIANGLE ).getShape().drawShape();
    }

    /**
     * Main method
     *
     * @param args
     */
    public static void main(String[] args) {

        ApplicationAbstractFactory application = new ApplicationAbstractFactory();
        application.drawShapes();
    }
}
